package se.citerus.dddsample.data;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import se.citerus.dddsample.domain.model.location.Location;
import se.citerus.dddsample.domain.model.location.UnLocode;

/**
 * Sample locations, for test purposes.
 */
public class SampleLocations {

	// 中国：香港
	public static final Location HONGKONG = new Location(new UnLocode("CNHKG"), "Hongkong");
	// 中国：杭州
	public static final Location HANGZOU = new Location(new UnLocode("CNHGH"), "Hangzhou");
	// 中国：上海
	public static final Location SHANGHAI = new Location(new UnLocode("CNSHA"), "Shanghai");

	// 美国：芝加哥
	public static final Location CHICAGO = new Location(new UnLocode("USCHI"), "Chicago");
	// 美国：纽约
	public static final Location NEWYORK = new Location(new UnLocode("USNYK"), "New York");
	// 美国：达拉斯
	public static final Location DALLAS = new Location(new UnLocode("DAL"), "Dallas");

	// 澳大利亚：墨尔本
	public static final Location MELBOURNE = new Location(new UnLocode("AUMEL"), "Melbourne");

	// 瑞典：斯德哥尔摩
	public static final Location STOCKHOLM = new Location(new UnLocode("SESTO"), "Stockholm");
	// 瑞典：哥德堡
	public static final Location GOTHENBURG = new Location(new UnLocode("SEGOT"), "Göteborg");

	// 芬兰：赫尔辛基
	public static final Location HELSINKI = new Location(new UnLocode("FIHEL"), "Helsinki");

	// 日本：东京
	public static final Location TOKYO = new Location(new UnLocode("JPTOK"), "Tokyo");
	// 德国：汉堡
	public static final Location HAMBURG = new Location(new UnLocode("DEHAM"), "Hamburg");
	// 荷兰：鹿特丹
	public static final Location ROTTERDAM = new Location(new UnLocode("NLROT"), "Rotterdam");

	public static final Map<UnLocode, Location> ALL = new HashMap<UnLocode, Location>();

	static {
		for (Field field : SampleLocations.class.getDeclaredFields()) {
			if (field.getType().equals(Location.class)) {
				try {
					Location location = (Location) field.get(null);
					ALL.put(location.unLocode(), location);
				} catch (IllegalAccessException e) {
					throw new RuntimeException(e);
				}
			}
		}
	}

	public static List<Location> getAll() {
		return new ArrayList<Location>(ALL.values());
	}

	public static Location lookup(UnLocode unLocode) {
		return ALL.get(unLocode);
	}

}
